import { defineStore } from "pinia";
import { reqHospitalDetail, reqHospitalDeparment } from '@/api/hospital.ts';
import type { HosPitalDetail, HospitalDetail,
    DepartmentResponseData } from '@/api/type_hosp.ts'
import type {DetailState} from "@/store/modules/type_hosp_data.ts";

const useHospitalDetailStore = defineStore('HospitalDetail', {
    state: (): DetailState => {
        return {
            //医院详情的数据
            hospitalInfo: ({} as HosPitalDetail),
            //存储医院科室的数据
            departmentArr: []
        }
    },
    actions: {
        //获取医院详情的方法
        async getHospital(hoscode: string) {
            let result: HospitalDetail = await reqHospitalDetail(hoscode);
            if (result.code == 200) {
                this.hospitalInfo = result.data;
            }
        },
        //获取某一个医院科室的数据
        async getDepartment(hoscode: string) {
            let result: DepartmentResponseData = await reqHospitalDeparment(hoscode);
            if (result.code == 200) {
                this.departmentArr = result.data;
            }
        }
    },
    getters: {}
})



export default useHospitalDetailStore;